﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.pad
{
    public partial class CustPartEntityProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<CustPartEntity> entryList = new List<CustPartEntity>();

            CustPartEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new CustPartEntity();
                    entry.Bin = item[CustPartEntity.BIN].ToString();
                    entry.BinDesc = item[CustPartEntity.BINDESC].ToString();
                    entry.Company = item[CustPartEntity.COMPANY].ToString();
                    entry.CustID = item[CustPartEntity.CUSTID].ToString();
                    entry.CustomerPart = item[CustPartEntity.CUSTOMER_PART].ToString();
                    entry.Description = item[CustPartEntity.DESCRIPTION].ToString();
                    entry.LotNumber = item[CustPartEntity.LOT_NUMBER].ToString();
                    entry.Name = item[CustPartEntity.NAME].ToString();
                    entry.OnHand = decimal.Parse(item[CustPartEntity.ON_HAND].ToString());
                    entry.Part = item[CustPartEntity.PART].ToString();
                    entry.PartDescription = item[CustPartEntity.PARTDESCRIPTION].ToString();
                    entry.WareDesc = item[CustPartEntity.WAREDESC].ToString();
                    entry.Warehouse = item[CustPartEntity.WAREHOUSE].ToString();
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
